package cn.schoolwow.util.domain.query.reflection;

import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.QuickFlowBuilder;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.util.module.query.reflection.domain.ReflectionOption;
import cn.schoolwow.util.module.query.reflection.service.GetClassFieldArrayFlow;
import cn.schoolwow.util.module.query.reflection.service.GetClassFieldFlow;

import java.lang.reflect.Field;
import java.util.List;

public class QueryReflectionResponse {
    private static QuickFlow reflectionQuickFlow = QuickFlowBuilder.newInstance();

    public QueryReflectionResponse(ReflectionOption reflectionOption) {
        this.reflectionQuickFlow.putContextThreadLocalInstanceData(reflectionOption);
    }

    /**获取字段列表*/
    public List<Field> getFieldList(){
        FlowContext flowContext = reflectionQuickFlow.executeFlow(new GetClassFieldArrayFlow());
        List<Field> fieldList = (List<Field>) flowContext.getData("fieldList");
        return fieldList;
    }

    /**获取指定字段*/
    public Field getField(String fieldName){
        FlowContext flowContext = reflectionQuickFlow.startFlow(new GetClassFieldFlow())
                .putCurrentCompositeFlowData("fieldName", fieldName)
                .execute();
        Field field = flowContext.getData("field", Field.class);
        return field;
    }
}
